import request from '@/utils/request'
import type {
  SpuResponseData,
  TradeMarkResponseData,
  SpuImageResponseData,
  SaleAttrResponseData,
  AllSaleAttrResponseData,
  SpuData
} from './type'

enum API {
  GETSPU_URL = '/admin/product/',
  GETTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  FETSPUIMAGE_URL = '/admin/product/spuImageList/',
  GETSALEATTR_URL = '/admin/product/spuSaleAttrList/',
  ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
  SAVESPU_URL = '/admin/product/saveSpuInfo',
  UPDATESPU_URL = '/admin/product/updateSpuInfo',
  DELETESPU_URL = '/admin/product/deleteSpu/'
}

export const getSpuService = (
  page: number,
  limit: number,
  category3Id: number | string
) =>
  request.get<any, SpuResponseData>(API.GETSPU_URL + `${page}/${limit}`, {
    params: {
      category3Id
    }
  })

// 获取所有品牌
export const getAllTradeMarkService = () =>
  request.get<any, TradeMarkResponseData>(API.GETTRADEMARK_URL)

// 获取spu图片
export const getSpuImageService = (spuId: number | string) =>
  request.get<any, SpuImageResponseData>(API.FETSPUIMAGE_URL + spuId)

// 获取spu销售属性
export const getAttrSaleService = (spuId: number | string) =>
  request.get<any, SaleAttrResponseData>(API.GETSALEATTR_URL + spuId)

// 获取所有销售属性
export const getAllSaleAttrService = () =>
  request.get<any, AllSaleAttrResponseData>(API.ALLSALEATTR_URL)

// 添加SPU
export const addSpuService = (data: SpuData) =>
  request.post<any, any>(API.SAVESPU_URL, data)

// 修改SPU
export const updateSpuService = (data: SpuData) =>
  request.post<any, any>(API.UPDATESPU_URL, data)

// 删除SPU
export const deleteSpuService = (spuId: number | string) =>
  request.delete<any, any>(API.DELETESPU_URL + spuId)
